package com.zhoust.fastdome.business.service.impl;

import com.zhoust.fastdome.business.entity.User;
import com.zhoust.fastdome.business.dao.UserMapper;
import com.zhoust.fastdome.business.service.UserService;
import com.zhoust.fastdome.emnu.ExceptionEnum;
import com.zhoust.fastdome.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author zhoust
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    @Override
    public String getUserById(String id) {
        User user = userMapper.selectById(id);
        return user.toString();
    }
    @Override
    public String getUserByIdException(String id) {
        User user = userMapper.selectById(id);
        // 模拟业务异常
        int i=5/0;
        return user.toString();
    }
    @Override
    public String getUserByIdBusinessException(String id) {
        User user = userMapper.selectById(id);
        // 模拟业务异常
        if("1".equals(id)){
            throw new BusinessException("400","id为1的数据不支持查询。");
        }
        return user.toString();
    }
    @Override
    public String getUserByIdBusinessExceptionByEnumOne(String id) {
        User user = userMapper.selectById(id);
        // 模拟业务异常
        if("1".equals(id)){
            ExceptionEnum.BUSINESS_NOT_ONE.ThrowException();
        }
        return user.toString();
    }
    @Override
    public String getUserByIdBusinessExceptionByEnumTwo(String id) {
        User user = userMapper.selectById(id);
        // 模拟业务异常
        if("look".equals(id)){
            // 可以动态拼接异常信息
            ExceptionEnum.ERR_NOT_LOOK.ThrowException("你说对吧"+id);
        }
        return user.toString();
    }
}
